<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .root{
            width: 400px;
            height: 400px;
            background-color: yellow;
        }
        .box{
            width:100px;
            height:100px;
            background-color: red;
        }

    </style>
</head>
<body>
    <button id="btn">按钮</button>
    <a href="https://www.baidu.com" id="a">百度</a>

    <div class="root" id="root">
        <div class="box" id="box"></div>
    </div>

    <script>
        var btn = document.getElementById('btn')
        btn.onclick = function(e){
            console.log(e.target);
            console.log(e.type);
        }

        var a = document.getElementById('a')
        a.onclick = function(e){
            e.preventDefault(); // 阻止默认行为
            console.log('点击了百度链接');
        }

        var root = document.getElementById('root')
        var box = document.getElementById('box')
        root.onclick = function(e){
            console.log('点击了黄色区域');
            console.log(e.target);
        }
        box.onclick = function(e){
            console.log('点击了红色区域');
            console.log(e.target);
            // 阻止事件冒泡
            e.stopPropagation();
        }

    </script>

</body>
</html>